package com.wenx.completablefuture;

/**
 * 折扣类
 */
public class Discount {
    public enum Code {
        NONE(0), SILVER(5), GOLD(10), PLATINUM(15), DIAMOND(20);
        private final int percentage;
        Code(int percentage) {
            this.percentage = percentage;
        }
    }

    public static String applyDiscount(Quote quote) {
        //将折扣代码应 用于商品最初 的原始价格
        return quote.getShopName() + " price is "
                + Discount.apply(quote.getPrice(), quote.getDisCountCode());
    }

    private static double apply(double price, Code code) {
        Shop shop = new Shop();
        //模拟Discount 服务响应的延迟
        shop.delay();
        return price * (100 - code.percentage) / 100;
    }
}
